Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: optimization of functional tests #6521

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

knst
Copy link
Collaborator

@knst knst commented Jan 6, 2025

Issue being fixed or feature implemented

Functional tests running locally takes too long time; and limitation is not even CPU and RAM for many of them.
This PR helps to speed some of the functional tests.

What was done?

Not much has been done, but some of the low-hanging fruit has been picked:

How Has This Been Tested?

Before this PR:

TEST                       | STATUS    | DURATION

feature_llmq_chainlocks.py | ✓ Passed  | 230 s
feature_maxuploadtarget.py | ✓ Passed  | 291 s
feature_mnehf.py           | ✓ Passed  | 109 s

ALL                        | ✓ Passed  | 630 s (accumulated) 

With these optimizations:

TEST                       | STATUS    | DURATION

feature_llmq_chainlocks.py | ✓ Passed  | 123 s
feature_maxuploadtarget.py | ✓ Passed  | 191 s
feature_mnehf.py           | ✓ Passed  | 86 s

ALL                        | ✓ Passed  | 400 s (accumulated) 

CI finishes 2 minutes faster (for non-tsan):
https://gitlab.com/dashpay/dash/-/jobs/8739701280
https://gitlab.com/dashpay/dash/-/jobs/8776172870

Size of artefacts on CI is slightly smaller (4 MB smaller for ubsan): 759 -> 755MB.

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@knst knst added this to the 22.1 milestone Jan 6, 2025
Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

The pull request introduces modifications across three functional test files: feature_llmq_chainlocks.py, feature_maxuploadtarget.py, and feature_mnehf.py. In feature_llmq_chainlocks.py, the changes focus on enhancing timeout parameters and replacing direct time sleep calls with more dynamic wait_until functions for chainlock-related tests. The feature_maxuploadtarget.py modification involves removing a synchronization line in the peer-to-peer connection test. In feature_mnehf.py, the changes include updating the test parameter initialization, adding logging statements, modifying block generation logic, and introducing a new method check_ehf_activated to verify the Enforcement Height Feature (EHF) activation. These modifications improve timing control, streamline test logic, and enhance code clarity across the different functional test scenarios.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a267293 and 9bec526.

📒 Files selected for processing (3)
  • test/functional/feature_llmq_chainlocks.py (4 hunks)
  • test/functional/feature_maxuploadtarget.py (0 hunks)
  • test/functional/feature_mnehf.py (6 hunks)
💤 Files with no reviewable changes (1)
  • test/functional/feature_maxuploadtarget.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Dependencies (linux64, x86_64-pc-linux-gnu)
  • GitHub Check: Build Dependencies (arm-linux, arm-linux-gnueabihf)
🔇 Additional comments (7)
test/functional/feature_mnehf.py (4)

27-27: LGTM! Improved code clarity and documentation.

The changes enhance readability by:

  1. Simplifying the extra_args initialization using list multiplication
  2. Adding a clear logging statement about consensus rules

Also applies to: 124-124


166-174: LGTM! Optimized test execution.

The changes improve test efficiency by:

  1. Reducing loop iterations while maintaining the same block count
  2. Generating blocks in larger batches
  3. Adding a node restart test during the process

185-186: LGTM! Consistent with optimization pattern.

Generating blocks in larger batches improves test execution time.


Line range hint 197-232: LGTM! Excellent improvement to test reliability.

The changes enhance test robustness by:

  1. Replacing static sleep with dynamic wait_until mechanism
  2. Properly handling time advancement with mocktime
  3. Adding clear verification of EHF activation
test/functional/feature_llmq_chainlocks.py (3)

86-86: LGTM! Added explicit timeout.

Adding a specific timeout value improves test reliability and clarity.


159-162: LGTM! Improved waiting mechanism.

Replaced static sleep with dynamic wait_until, enhancing test reliability with explicit timeout.


200-207: LGTM! Well-structured test helper method.

The new test_cb helper method:

  1. Encapsulates chainlock verification logic
  2. Improves code readability
  3. Makes the test more maintainable

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
test/functional/feature_mnehf.py (4)

28-28: Prefer adding a short explanatory comment for large numeric parameters.

Using 999999999999 conveys that the activation will happen almost indefinitely, but it might be helpful to comment on why such a large parameter is used (e.g., for test flexibility or to prevent actual activation during tests).


167-169: Suggestion: Replace arithmetic with direct constants for clarity.

Writing for _ in range(2) might be more readable than for _ in range(4 // 2) unless the 4 is a placeholder for dynamic usage.

-        for _ in range(4 // 2):
+        for _ in range(2):
             self.check_fork('started')
             self.generate(node, 2)

172-175: Clarify the intention behind range(4 // 2) and conditional restarts.

Consider replacing range(4 // 2) with range(2) and adding in-code comments detailing the rationale for restarting nodes on the second iteration.


198-200: Minor improvement: Clarify the relationship between block generation and node restarts.

Generating 4 blocks, then restarting node 0, might benefit from a brief comment indicating why this sequence is necessary (e.g., to simulate a specific network condition).

test/functional/feature_llmq_chainlocks.py (1)

186-186: Inline comment recommended.

Explain why a 5-second timeout is chosen here. This helps maintain clarity for future maintainers or runs in slower test environments.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5787c9 and a267293.

📒 Files selected for processing (3)
  • test/functional/feature_llmq_chainlocks.py (4 hunks)
  • test/functional/feature_maxuploadtarget.py (0 hunks)
  • test/functional/feature_mnehf.py (6 hunks)
💤 Files with no reviewable changes (1)
  • test/functional/feature_maxuploadtarget.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Dependencies (linux64, x86_64-pc-linux-gnu)
  • GitHub Check: Build Dependencies (arm-linux, arm-linux-gnueabihf)
🔇 Additional comments (7)
test/functional/feature_mnehf.py (4)

125-125: Log message aligns with the test's scenario.

This logging statement clarifies assumptions for EHF signals pre-V20. No issues here.


186-187: No issues identified.

Generating 4 blocks and checking fork status is consistent with the test flow. Good use of check_fork('defined') to validate state.


225-225: Informative logging.

Log messages help track the test flow and are especially crucial for debugging. Good practice.


229-233: Nicely encapsulated checking mechanism with wait_until.

Introducing check_ehf_activated(self) is a clear improvement over static sleep usage. Well done.

test/functional/feature_llmq_chainlocks.py (3)

87-87: Introduced a shorter timeout.

A 5-second timeout may be sufficient in most environments, but consider leaving a margin or making it configurable if network latency can vary significantly.


160-163: Good use of wait_until for dynamic assertions.

These changes replace sleep-based timing with condition-based waits, improving reliability. Ensure that large regressions in slow environments won't cause unwanted timeouts.


200-206: Condensed condition checks with a helper function.

Defining test_cb(self) clarifies the readiness condition. The logic is reversed (return False if chainlock is set), which is valid as long as the calling condition expects a boolean outcome. Good approach.

@knst knst force-pushed the functional-tests-speedup branch from a267293 to 9bec526 Compare January 6, 2025 13:35
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 9bec526

@PastaPastaPasta
Copy link
Member

Before

TEST                       | STATUS    | DURATION

feature_llmq_chainlocks.py | ✓ Passed  | 259 s
feature_maxuploadtarget.py | ✓ Passed  | 299 s
feature_mnehf.py           | ✓ Passed  | 126 s

after

TEST                       | STATUS    | DURATION

feature_llmq_chainlocks.py | ✓ Passed  | 144 s
feature_maxuploadtarget.py | ✓ Passed  | 199 s
feature_mnehf.py           | ✓ Passed  | 108 s

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 9bec526

@PastaPastaPasta PastaPastaPasta merged commit b8decb8 into dashpay:develop Jan 7, 2025
23 checks passed
@knst knst deleted the functional-tests-speedup branch January 7, 2025 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants